package com.fdb.smcts.core.util;

import java.util.HashMap;
import java.util.Map;

import org.springframework.cglib.beans.BeanMap;

public class MapBeanUtil {

	/**
	 * 
	 * @Title: beanToMap
	 * @Description: javabean转map
	 * @param bean
	 * @return
	 */
	public static <T> Map<String, Object> beanToMap(T bean) {
		Map<String, Object> beanMap = new HashMap<>(16);
		if (bean != null) {
			BeanMap tempMap = BeanMap.create(bean);
			for (Object key : tempMap.keySet()) {
				String putKey = String.valueOf(key);
				Object putValue = tempMap.get(key);
				beanMap.put(putKey, putValue);
			}
		}
		return beanMap;
	}

	/**
	 * 
	 * @Title: mapToBean
	 * @Description: map转javabean
	 * @param beanMap
	 * @param bean
	 * @return
	 */
	public static <T> T mapToBean(Map<String, Object> beanMap, T bean) {
		BeanMap tempMap = BeanMap.create(bean);
		tempMap.putAll(beanMap);
		return bean;
	}
}
